package com.lijunhuayc.sample;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;

import com.lijunhuayc.downloader.utils.LogUtils;

public class ImageButton1 extends AppCompatButton {

    private Paint mPaint;
    private ColorDrawable mDrawable;


    private long max;
    private float mPrecent;

    public ImageButton1(Context context) {
        super(context);
    }

    public ImageButton1(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setColor(Color.RED);

        mDrawable = new ColorDrawable(Color.RED);
    }

    public ImageButton1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        LogUtils.d("TAG", "2");
        int left = 0;
        int right = (int) (mPrecent * getWidth());
        int bottom = getHeight();
        int top = 0;
        canvas.drawRect(left,top,right,bottom,mPaint);
       /* mDrawable.setBounds((int) left, (int) top, (int) right, (int) bottom);
        mDrawable.draw(canvas);*/
       // invalidate();
        super.onDraw(canvas);
    }

    public void setProgress(int progress) {
        LogUtils.d("TAG", "1");
        mPrecent = (float) (progress * 1.0 / 100);

    }

    public void setMax(long max) {
        this.max = max;
    }

}
